(function() {
    'use strict';

    /**
     * @ngdoc directive
     * @name webApp.directive:pager
     * @description
     * # pager 
     */
    angular.module('webApp')
        .run(["$templateCache", "dataService",
            function($templateCache, dataService) {
                var tplName = "views/directives.cainum.html";
                dataService.tpl(tplName).then(function(html) {
                    $templateCache.put(tplName, html);
                });
            }
        ])
        .directive('cainumList', function() {
            return {
                restrict: "E",
                template: "<a href='javascript:void(0);'  class='sui-btn btn-link' ng-click='clickinit();'>添加抽奖</a>",
                scope: {
                    callback: "&",

                },
                controller: ['$templateCache', '$rootScope', '$scope', '$compile', 'dataService', '$timeout', function($templateCache, $rootScope, $scope, $compile, dataService, $timeout) {
                    var showDialog = null
                    $scope.cid = "";
                    var cpath = "";
                    $scope.clickinit=function(){
                    	$scope.init().then(function(){
                    		$scope.showPage();
                    	})
                    }
                    $scope.init=function(pageNo){
                    	pageNo=pageNo?pageNo:1;
                        $scope.pageSize=10;

                        var query = {};
			            query.content = {
			                "page_no": pageNo ? pageNo : "1",
			                "page_size": $scope.pageSize,
			                "store_id": $rootScope.store_id
			            };

			            return dataService.luckydrawGet(query).then(function(list) {
			                if (list) {
			                    $scope.draw_list = list.draw_list;
			                    $scope.draw_list_count = list.total_count;
			                }
			            });
                    }
                    $scope.addcaishu=function(draw){
//                     	console.error("draw",draw);
                        $scope.draw=draw;
                    }
                    $scope.showPage = function() {
                        showDialog = $.alert({
                            backdrop: 'static',
                            keyboard: true,
                            title: '<span>+选择抽奖</span>',
                            body: $templateCache.get("views/directives.cainum.html"),
                            okBtn: '{{"ok" | translate}}',
                            closeBtn: true,
                            transition: true,
                            // hasfoot: false,
                            height:"300px",
                            width: '880px',
                            show: function(e) {
                                $compile($(e.currentTarget).contents())($scope);
                                return true;
                            },
                            okHide: function(e) {
                                 if(_.size($scope.draw)>0){
                                    	console.log("draw_id",$scope.draw);
                                        $scope.callback({draw_id:$scope.draw.draw_id});
                                }
                            },
                        });
                    }

                }],
                link: function(scope, element, attrs, ueditor) {}
            }
        });
})();